package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "APP套餐管理")
@Slf4j
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    // 套餐列表
    @ApiOperation(value = "列表查询套餐")
    @Cacheable(value = "appSetmeal",key = "#categoryId")
    @GetMapping("/list")
    public ResultInfo lists(Long categoryId,Integer status){

        List<Setmeal> listSetmeal = setmealService.list(categoryId,status);

        return ResultInfo.success( listSetmeal );
    }

    // 查看套餐详情 id查询
    @ApiOperation(value = "id查询套餐详情")
    @Cacheable(value = "appSetmeal",key = "#id")
    @GetMapping("dish/{id}")
    public ResultInfo setmealById(@PathVariable Long id){

        List<Dish> dishList = setmealService.listById(id);

        return ResultInfo.success(dishList);

    }

}
